package cn.zhentao.controller;

import cn.zhentao.pojo.Role;
import cn.zhentao.pojo.User;
import cn.zhentao.service.ZhService;
import cn.zhentao.vo.ZhVo;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.io.Serializable;
import java.util.List;

@RestController
@RequestMapping("/zh")
public class ZhController implements Serializable {
@Autowired
    private ZhService zhService;
//=====cx
    @GetMapping("/finda")
    public PageInfo<ZhVo> finda(@RequestParam("pageNum")Integer pageNum, @RequestParam("pageSize")Integer pageSize,@RequestParam String uname){
        PageHelper.startPage(pageNum,pageSize);
        List<ZhVo> finda = zhService.finda(uname);
        for (ZhVo userVo : finda) {
            List<Role> findr = zhService.findr(userVo.getUid());
            userVo.setList(findr);
        }
        PageInfo<ZhVo> userVoPageInfo = new PageInfo<>(finda);
        return userVoPageInfo;
    }
//=====zcx
    @GetMapping("/findu")
    public List<Role>findu(){
        List<Role> findu = zhService.findu();
        return findu;
    }
//=====cxr
@PostMapping("/findr")
    public List<Role>findr(@RequestParam Integer uid){
        List<Role> findr = zhService.findr(uid);
        return findr;
    }
//=====login
    @PostMapping("/login")
    public ZhVo login(@RequestParam String username,@RequestParam String password){
        ZhVo findn = zhService.findn(username, password);
        return findn;
    }
//=====tj
    @PostMapping("/add")
    public void add(@RequestBody ZhVo zhVo){
        zhService.add(zhVo);
    }
//=====del
    @DeleteMapping("/del")
    public int del(@RequestBody Integer[]uid){
        int del = zhService.del(uid);
        return del;
    }
//=====upd
    @PostMapping("/update")
    public int update(@RequestBody ZhVo zhVo){
        zhService.updateu(zhVo);
        return 1;
    }
//=====updz
@PostMapping("/updatez")
public int updatez(@RequestBody ZhVo zhVo){
    zhService.updatez(zhVo);
    return 1;
}
//=====mo
    @PostMapping ("/findmo")
    public List<ZhVo>findmo(@RequestBody String uname){
        List<ZhVo> findmo = zhService.findmo(uname);
        return findmo;
    }
//=====finduid
    @PostMapping("/finduid")
    public List<ZhVo>finduid(@RequestParam Integer uid){
        List<ZhVo> finduid = zhService.finduid(uid);
        return finduid;
    }
//    ====
    @PostMapping("/findrc")
    public Role findrc(@RequestParam Integer uid){
        Role findrc = zhService.findrc(uid);
        return findrc;
    }
}


